package com.joysuch.wwyt.bp.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joysuch.wwyt.bp.bean.dto.KeyValueDTO;
import com.joysuch.wwyt.bp.entity.BpCommonNotifyRel;
import com.joysuch.wwyt.bp.enums.CommonNotifyRelType;
import com.joysuch.wwyt.bp.mapper.BpCommonNotifyRelMapper;
import com.joysuch.wwyt.bp.service.BpCommonNotifyRelService;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class BpCommonNotifyRelServiceImpl extends ServiceImpl<BpCommonNotifyRelMapper, BpCommonNotifyRel> implements BpCommonNotifyRelService {

    @Override
    public Map<Long, Integer> countMapByRelAndType(Collection<Long> relIds, CommonNotifyRelType type) {
        if (CollectionUtil.isEmpty(relIds) || Objects.isNull(type)) {
            return Collections.emptyMap();
        }
        List<KeyValueDTO<Long, Integer>> countList = baseMapper.countByPlanAndType(relIds, type.getCode());
        if (CollectionUtil.isEmpty(countList)) {
            return Collections.emptyMap();
        }
        return countList.stream().collect(Collectors.toMap(KeyValueDTO::getKey, KeyValueDTO::getValue));
    }

}
